<html>
<head><meta charset="utf-8"><title>Allow unwinding from extern &quot;C&quot; by default · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html">Allow unwinding from extern &quot;C&quot; by default</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178725735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178725735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178725735">(Oct 22 2019 at 06:06)</a>:</h4>
<p>I've been looking into how C++ deals with exceptions in FFI and come up with this idea: what if we made extern "C" allow unwinding by default, unless specifically marked with a <code>#[no_unwind]</code> attribute.</p>



<a name="178725815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178725815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178725815">(Oct 22 2019 at 06:08)</a>:</h4>
<p>This matches the behavior of C++ in a few ways:<br>
- <code>extern "C"</code> functions in C++ are allowed to throw exceptions.<br>
- Functions declared <code>noexcept</code> cannot throw exceptions<br>
- Functions defined <code>noexcept</code> will call <code>std::terminate</code> if an uncaught exception reaches them.</p>



<a name="178728245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728245">(Oct 22 2019 at 06:55)</a>:</h4>
<p>I believe this matches the advice given to me by nlewycky when I consulted them about the unwinding issue some time ago. (I don't think they've personally chimed in on any of the issues or RFCs except to describe their personal use case here: <a href="https://github.com/rust-lang/rfcs/pull/2753#issuecomment-527587083" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2753#issuecomment-527587083">https://github.com/rust-lang/rfcs/pull/2753#issuecomment-527587083</a>)</p>



<a name="178728311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728311">(Oct 22 2019 at 06:56)</a>:</h4>
<p>nlewycky is an ex-LLVM dev, which I expect informs their opinion on the matter.</p>



<a name="178728396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728396">(Oct 22 2019 at 06:58)</a>:</h4>
<p>That said, <code>extern "C"</code> is already substantially different from its C++ counterpart, because it doesn't prevent name-mangling. (<code>#[no_mangle]</code> is arguably closer to the semantics of C++'s <code>extern "C"</code> than Rust's <code>extern "C"</code> is.)</p>



<a name="178728427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728427">(Oct 22 2019 at 06:59)</a>:</h4>
<p>I just feel that we should have the safe version be the default, and if you really want to tell the optimizer that an FFI function does not unwind then you can add an attribute.</p>



<a name="178728713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728713">(Oct 22 2019 at 07:04)</a>:</h4>
<p>Well....</p>



<a name="178728721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728721">(Oct 22 2019 at 07:04)</a>:</h4>
<p>Have you read much or all of the discussions in RFCs 2699 and 2753?</p>



<a name="178728806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728806">(Oct 22 2019 at 07:06)</a>:</h4>
<p>The main arguments against that view, as I understood them, were that (1) _exposing_ unwinding (from Rust <code>extern "C"</code> functions) would be _less_ safe than <code>abort</code>ing, and (2) having a different assumption about unwinding for <code>extern "C"</code> depending on whether the function is being "imported" vs defined would be inconsistent and therefore confusing.</p>



<a name="178728855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728855">(Oct 22 2019 at 07:07)</a>:</h4>
<p>I am of the opinion that the "consistently conservative" behavior would be to prohibit _exposing_ unwinding by default (i.e. Rust <code>extern "C"</code> functions would have the abort logic), but to assume that "imported" <code>extern "C"</code> functions may unwind (and that the caller therefore needs a landing pad).</p>



<a name="178728915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178728915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178728915">(Oct 22 2019 at 07:08)</a>:</h4>
<p>Let me get the link to the prior discussion....</p>



<a name="178729277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178729277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178729277">(Oct 22 2019 at 07:15)</a>:</h4>
<p>Here's where I brought up the idea that the defaults should be opposites: <a href="https://github.com/rust-lang/rfcs/pull/2753#issuecomment-528945332" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2753#issuecomment-528945332">https://github.com/rust-lang/rfcs/pull/2753#issuecomment-528945332</a></p>



<a name="178729322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178729322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178729322">(Oct 22 2019 at 07:16)</a>:</h4>
<p>I'm not sure anyone in either RFC recommended making the default <code>unwind(allow)</code> for both cases.</p>



<a name="178729338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178729338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178729338">(Oct 22 2019 at 07:16)</a>:</h4>
<p>A major concern there is that without <code>-fexceptions</code>, C code on most major non-Windows platforms can't properly support unwinding.</p>



<a name="178729738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178729738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178729738">(Oct 22 2019 at 07:25)</a>:</h4>
<p>Not having -fexceptions doesn't block unwinding though, unwinding through C code still works fine.</p>



<a name="178729750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178729750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178729750">(Oct 22 2019 at 07:25)</a>:</h4>
<p>Unwinding just skips frames with no unwind info.</p>



<a name="178729910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178729910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178729910">(Oct 22 2019 at 07:29)</a>:</h4>
<p>Hmm technically LLVM says it's UB because we use the <code>nounwind</code> attribute</p>



<a name="178729933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178729933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178729933">(Oct 22 2019 at 07:29)</a>:</h4>
<p>for any ABI specifier where we don't <code>abort</code> on unwind, we'd stop emitting <code>nounwind</code></p>



<a name="178729997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178729997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178729997">(Oct 22 2019 at 07:30)</a>:</h4>
<p>...I did not realize that it's well-defined behavior to not have landing pads in intermediate frames.</p>



<a name="178730029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178730029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178730029">(Oct 22 2019 at 07:31)</a>:</h4>
<p>That definitely changes my understanding of <code>-fexceptions</code>. I had thought that without <code>-fexceptions</code>, the behavior of a C++ <code>throw</code> crossing over C frames would be undefined.</p>



<a name="178730055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178730055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178730055">(Oct 22 2019 at 07:31)</a>:</h4>
<p>....in an actually-dangerous way, not just a "the C++ standard can't state what the C language does, and C doesn't mention exceptions, therefore it's undefined" way.</p>



<a name="178730221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178730221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178730221">(Oct 22 2019 at 07:34)</a>:</h4>
<p>Here is Centril's response to my statement (linked above) that there should be opposite defaults: <a href="https://github.com/rust-lang/rfcs/pull/2753#issuecomment-529084321" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2753#issuecomment-529084321">https://github.com/rust-lang/rfcs/pull/2753#issuecomment-529084321</a></p>



<a name="178730258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178730258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178730258">(Oct 22 2019 at 07:35)</a>:</h4>
<p>Though note that he's objecting to treating <code>extern "C"</code> function pointers (rather than import declarations) as unwind-allowed-by-default</p>



<a name="178730276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178730276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178730276">(Oct 22 2019 at 07:35)</a>:</h4>
<p>...but I think that the one would imply the other, since at the point of usage, function pointers have less associate information.</p>



<a name="178730337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178730337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178730337">(Oct 22 2019 at 07:36)</a>:</h4>
<p>There is also a separate argument in that thread about why <code>extern "C"</code> shouldn't unwind, namely, because of the name "C", since the C language doesn't have exceptions.</p>



<a name="178730360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178730360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178730360">(Oct 22 2019 at 07:37)</a>:</h4>
<p>Since <code>C</code> can in fact have unwinding (e.g. in Windows with SEH) and <code>extern "C"</code> is taken from C++ (not from C), I don't really agree with that particular argument.</p>



<a name="178730832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178730832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178730832">(Oct 22 2019 at 07:46)</a>:</h4>
<p>Can you think of any scenario where emitting a <code>panic</code> from Rust into foreign (C, C++, D, etc) code compiled with the corresponding backend would cause undefined behavior? (Assuming that the foreign code has no RAII or <code>finally</code> constructs, and assuming that it doesn't attempt to catch or otherwise interact with the unwind operation)</p>



<a name="178731058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178731058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178731058">(Oct 22 2019 at 07:50)</a>:</h4>
<p>If not, and if we have some confidence that this is considered "well defined" for the various platforms, then I would be strongly inclined to just change the (non) specification of Rust's <code>extern "C"</code> unwinding from "undefined" to "implementation defined".</p>



<a name="178731084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178731084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178731084">(Oct 22 2019 at 07:51)</a>:</h4>
<p>...and providing some kind of <code>unwind(abort)</code> annotation, for use anywhere in the language, since that seems potentially useful.</p>



<a name="178731294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178731294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178731294">(Oct 22 2019 at 07:54)</a>:</h4>
<p>With that said, I expect (based on the conversations in those RFCs) that not all the stakeholders would agree with this direction.</p>



<a name="178731402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178731402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178731402">(Oct 22 2019 at 07:56)</a>:</h4>
<p>Additionally, one benefit of having separate ABI strings for functions that can unwind versus those that can't is that the type system can ensure that the information is preserved even via function pointers. Of course, that also carries with it the downside of introducing a new incompatible function pointer type.</p>



<a name="178731899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178731899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178731899">(Oct 22 2019 at 08:02)</a>:</h4>
<p>Early on when this issue was being discussed, I asked on StackOverflow about "how undefined" the behavior _even with_ <code>-fexceptions</code> is. Here's one of the answers: <a href="https://stackoverflow.com/a/55818675/1858225" target="_blank" title="https://stackoverflow.com/a/55818675/1858225">https://stackoverflow.com/a/55818675/1858225</a></p>



<a name="178731933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178731933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178731933">(Oct 22 2019 at 08:03)</a>:</h4>
<p>I consider that answer unhelpful and probably wrong, but I'm certainly not an expert.</p>



<a name="178731993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178731993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178731993">(Oct 22 2019 at 08:04)</a>:</h4>
<p>In any case, it's an example of an attitude that makes me hesitant to push for letting exceptions escape from <code>extern "C"</code> in Rust by default.</p>



<a name="178732212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732212">(Oct 22 2019 at 08:08)</a>:</h4>
<p>Technically a Rust panic unwinding into C code (compiled without -fexceptions) would be UB. But in practice it would work as expected with the unwinder simply skipping the C frames.</p>



<a name="178732241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732241">(Oct 22 2019 at 08:09)</a>:</h4>
<p>Does the Itanium ABI not specify what happens when there aren't landing pads?</p>



<a name="178732247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732247">(Oct 22 2019 at 08:09)</a>:</h4>
<p>(in frames being crossed by an exception)</p>



<a name="178732277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732277">(Oct 22 2019 at 08:09)</a>:</h4>
<p>Nothing happens, it just continues unwinding.</p>



<a name="178732319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732319">(Oct 22 2019 at 08:10)</a>:</h4>
<p>Let me double check</p>



<a name="178732330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732330">(Oct 22 2019 at 08:10)</a>:</h4>
<p>If it does specify that, then wouldn't the behavior be implementation-defined on platforms supporting that ABI, as long as Rust says it is?</p>



<a name="178732389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732389">(Oct 22 2019 at 08:11)</a>:</h4>
<p>OK, so here's what happens. First of all, the C code must have unwinding tables. This is usually on by default, even without -fexceptions.</p>



<a name="178732458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732458">(Oct 22 2019 at 08:12)</a>:</h4>
<p>Ah! Okay, so that seems important - without unwinding tables, the behavior would be undefined even at the platform level, correct?</p>



<a name="178732478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732478">(Oct 22 2019 at 08:12)</a>:</h4>
<p>Without unwinding tables the C code is basically treated as "end-of-stack"</p>



<a name="178732486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732486">(Oct 22 2019 at 08:12)</a>:</h4>
<p>What does that mean?</p>



<a name="178732501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732501">(Oct 22 2019 at 08:13)</a>:</h4>
<p>Excluding the case of missing unwinding tables, I guess what I'm trying to say is that it seems like this is only UB because the various language standards don't say otherwise, but most (or all?) of the platforms providing the ABIs seem to actually provide well-defined behavior.</p>



<a name="178732506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732506">(Oct 22 2019 at 08:13)</a>:</h4>
<p>No handler found, unwinding fails, std::terminate is called (in C++)</p>



<a name="178732543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732543">(Oct 22 2019 at 08:13)</a>:</h4>
<p>So, still not UB!</p>



<a name="178732549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732549">(Oct 22 2019 at 08:13)</a>:</h4>
<p>If you search for <code>nounwind</code> in LLVM's LangRef, it talks about UB.</p>



<a name="178732570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732570">(Oct 22 2019 at 08:13)</a>:</h4>
<p>Right, I'm excluding <code>nounwind</code> in my thought process here</p>



<a name="178732645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732645">(Oct 22 2019 at 08:14)</a>:</h4>
<p>When LLVM compiles C code it uses <code>nounwind</code> everywhere. So it would be UB for a Rust panic to unwind through that code.</p>



<a name="178732651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732651">(Oct 22 2019 at 08:14)</a>:</h4>
<p>It seems like exceptions are perhaps much less dangerous and scary than I had been led to believe, at the ABI/platform level</p>



<a name="178732660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732660">(Oct 22 2019 at 08:14)</a>:</h4>
<p>Ahhh.</p>



<a name="178732661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178732661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178732661">(Oct 22 2019 at 08:14)</a>:</h4>
<p>(LLVM does generate unwind tables for C code though)</p>



<a name="178733225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178733225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178733225">(Oct 22 2019 at 08:22)</a>:</h4>
<p>But then again, the only thing LLVM uses <code>nounwind</code> for is optimizing away "dead" landing pads. Which there aren't any in C anyways. So it will work in practice.</p>



<a name="178733364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178733364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178733364">(Oct 22 2019 at 08:25)</a>:</h4>
<p>Hm, I can't find a reference for LLVM emitting <code>nounwind</code> on C code; does it still do so even with <code>-fexceptions</code>? (Surely not?)</p>



<a name="178734218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178734218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178734218">(Oct 22 2019 at 08:36)</a>:</h4>
<p>Try it on godbolt</p>



<a name="178734257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178734257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178734257">(Oct 22 2019 at 08:36)</a>:</h4>
<p><a href="https://godbolt.org/z/9eRIQs" target="_blank" title="https://godbolt.org/z/9eRIQs">https://godbolt.org/z/9eRIQs</a></p>



<a name="178748792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178748792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178748792">(Oct 22 2019 at 12:11)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> LLVM <code>nounwind</code> does not mean "does not unwind"</p>



<a name="178748802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178748802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178748802">(Oct 22 2019 at 12:11)</a>:</h4>
<p><code>nounwind</code> functions are allowed to unwind</p>



<a name="178748911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178748911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178748911">(Oct 22 2019 at 12:13)</a>:</h4>
<p>the more relevant questions are whether you want the unwind to run destructors or call abort (some safe Rust code requires destructors to run for soundness)</p>



<a name="178748930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178748930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178748930">(Oct 22 2019 at 12:13)</a>:</h4>
<p>notice that LLVM also has the <code>nouwtable</code> attribute as well</p>



<a name="178749051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178749051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178749051">(Oct 22 2019 at 12:14)</a>:</h4>
<p>also, when you talk about <code>extern "C"</code> you are not being specific if what you are proposing applies to function definitions, function declarations, or both</p>



<a name="178749091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178749091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178749091">(Oct 22 2019 at 12:15)</a>:</h4>
<p>Does <code>extern "C" { #[no_unwind] fn foo(); }</code> abort on unwinding under your proposal ? If so, how would that be implemented ?</p>



<a name="178749475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178749475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178749475">(Oct 22 2019 at 12:19)</a>:</h4>
<p>Finally, C++ <code>noexcept</code> is part of the C++ type system, but <code>#[no_unwind]</code> would not be.</p>



<a name="178749579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178749579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178749579">(Oct 22 2019 at 12:21)</a>:</h4>
<p>Would it be possible for users to somehow specify at a call site that calling a function does not unwind ?</p>



<a name="178752418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178752418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178752418">(Oct 22 2019 at 12:56)</a>:</h4>
<blockquote>
<p>Does <code>extern "C" { #[no_unwind] fn foo(); }</code> abort on unwinding under your proposal ? If so, how would that be implemented ?</p>
</blockquote>
<p>It would be UB on unwind (same as <code>extern noexcept</code> in C++).</p>



<a name="178752471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178752471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178752471">(Oct 22 2019 at 12:57)</a>:</h4>
<p>(In practice it still unwinds but destructors may have been optimized out by LLVM assuming that unwinding can't happen)</p>



<a name="178754432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754432">(Oct 22 2019 at 13:18)</a>:</h4>
<p>Also regarding LLVM <code>nounwind</code>:</p>
<blockquote>
<p>If the function does raise an exception, its runtime behavior is undefined.</p>
</blockquote>



<a name="178754439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754439">(Oct 22 2019 at 13:18)</a>:</h4>
<p>Keep reading</p>



<a name="178754516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754516">(Oct 22 2019 at 13:19)</a>:</h4>
<blockquote>
<p>However, functions marked nounwind may still trap or generate asynchronous exceptions.</p>
</blockquote>
<p>But we're talking about normal exceptions here.</p>



<a name="178754539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754539">(Oct 22 2019 at 13:19)</a>:</h4>
<p>Keep reading</p>



<a name="178754618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754618">(Oct 22 2019 at 13:20)</a>:</h4>
<p>In particular the note about SEH</p>



<a name="178754661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754661">(Oct 22 2019 at 13:20)</a>:</h4>
<p>Eh sure, but even then that's debatable.</p>



<a name="178754681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754681">(Oct 22 2019 at 13:20)</a>:</h4>
<p>Keep in mind we do use SJLJ unwinding on at least one target (iOS ARM32)</p>



<a name="178754687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754687">(Oct 22 2019 at 13:20)</a>:</h4>
<p>notice that <code>longjmp</code> on windows uses SEH, and it is correct to <code>longjmp</code> over <code>noexcept</code> functions</p>



<a name="178754727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754727">(Oct 22 2019 at 13:21)</a>:</h4>
<p>which are <code>nounwind</code></p>



<a name="178754948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178754948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178754948">(Oct 22 2019 at 13:24)</a>:</h4>
<p>Sure, but the key point here is that LLVM will optimize away destructors with the assumption that they are unreachable.</p>



<a name="178755004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755004">(Oct 22 2019 at 13:24)</a>:</h4>
<p>I don't know how we can explain that except through UB.</p>



<a name="178755015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755015">(Oct 22 2019 at 13:24)</a>:</h4>
<p>That's why I mentioned that the key thing about <code>nounwind</code> is whether destructors should or should not be run on unwinding</p>



<a name="178755035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755035">(Oct 22 2019 at 13:24)</a>:</h4>
<p>Not running destructors is ok, e.g., if the frame does not contain any destructors to run</p>



<a name="178755143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755143">(Oct 22 2019 at 13:26)</a>:</h4>
<p>When calling a function that's <code>nounwind</code>, if the function is actually unwound, destructors might or might not be run (it depends, its even possible that only some destructors would be run, but not all), but there is a lot of code for which the distinction does not matter.</p>



<a name="178755211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755211">(Oct 22 2019 at 13:27)</a>:</h4>
<p>Except that LLVM is clearly using the UB rule to allow itself to optimize away unreachable destructors. I don't think we should rely on LLVM's interpretation of UB remaining consistent.</p>



<a name="178755238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755238">(Oct 22 2019 at 13:27)</a>:</h4>
<p>We do not need to guarantee that destructors are / aren't run consistently</p>



<a name="178755316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755316">(Oct 22 2019 at 13:28)</a>:</h4>
<p>We just need to say that the behavior is unspecified, and that means that either all destructors run, no destructors run, or some destructors run, and that implementations do not need to write down nor guarantee what they do.</p>



<a name="178755360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755360">(Oct 22 2019 at 13:28)</a>:</h4>
<p>In practice, if your frame doesn't contain destructors, or the destructors are not required for safety, and you are ok with some or all of them not running, then you are fine.</p>



<a name="178755494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755494">(Oct 22 2019 at 13:30)</a>:</h4>
<p>(This is what we could say at the Rust side - how we lower this to LLVM would be a different matter, but on platforms such as windows, making them <code>nounwind</code> might be fine, because LLVM says that the behavior there is implementation-defined)</p>



<a name="178755740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755740">(Oct 22 2019 at 13:33)</a>:</h4>
<p>I disagree with your interpretation of LLVM's paragraph. I read it as: unwinding with an exception is UB, but unwinding with a trap or asynchronous exception is implementation-defined.</p>



<a name="178755860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178755860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178755860">(Oct 22 2019 at 13:34)</a>:</h4>
<p>LLVM can't remove the destructors unless it can prove that the destructors are only reachable through UB.</p>



<a name="178756489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178756489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178756489">(Oct 22 2019 at 13:40)</a>:</h4>
<p>So are you arguing that SEH is synchronous ?</p>



<a name="178756609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178756609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178756609">(Oct 22 2019 at 13:41)</a>:</h4>
<p>Or how do you interpret the behavior of <code>nounwind</code> on windows, where SEH exceptions are asynchronous, and that's the mechanism that <code>longjmp</code> and C++ use ?</p>



<a name="178756625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178756625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178756625">(Oct 22 2019 at 13:41)</a>:</h4>
<p>It can be either. If you raise an exception yourself by calling <code>RaiseException</code> then it is. If you trigger an exception through a trap then it isn't.</p>



<a name="178756808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178756808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178756808">(Oct 22 2019 at 13:43)</a>:</h4>
<p><code>RaiseException</code> is what <code>longjmp</code> uses</p>



<a name="178756810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178756810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178756810">(Oct 22 2019 at 13:43)</a>:</h4>
<p>Synchronous exception = something you explicitly throw<br>
Trap = a faulting instruction<br>
Asynchronous exception = an exceptions injected into your thread from another thread</p>



<a name="178757030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757030">(Oct 22 2019 at 13:45)</a>:</h4>
<p>Hmm <code>longjmp</code> is wierd.</p>



<a name="178757143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757143">(Oct 22 2019 at 13:46)</a>:</h4>
<p>So under your interpretation, because <code>longjmp</code> on windows uses a synchronous exception, it would be UB for it to unwind out of a <code>noexcept</code> function (which is <code>nounwind</code>). However, AFAICT from LLVM and the MSVC docs, it isn't, and that's actually guaranteed to work</p>



<a name="178757235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757235">(Oct 22 2019 at 13:47)</a>:</h4>
<p>MSVC mentions <a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/longjmp?view=vs-2019" target="_blank" title="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/longjmp?view=vs-2019">here</a>:</p>
<blockquote>
<p>If the code is compiled by using /EHs or /EHsc and the function that contains the longjmp call is noexcept then local objects in that function may not be destructed during the stack unwind.</p>
</blockquote>



<a name="178757325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757325">(Oct 22 2019 at 13:48)</a>:</h4>
<p>I think we would need a confirmation from LLVM devs to guarantee that the only consequence of misusing <code>nounwind</code> is that destructors may not get called.</p>



<a name="178757389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757389">(Oct 22 2019 at 13:48)</a>:</h4>
<p>And yes, <code>longjmp</code> is considered a synchronous exception by my definition.</p>



<a name="178757405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757405">(Oct 22 2019 at 13:48)</a>:</h4>
<p>The same happens in the Itanium-C++ ABI (for the Itanium target), where <code>longjmp</code> uses <code>Unwind_ForceUnwind</code> to unwind through frames, and it can actually unwind through <code>noexcept</code> functions</p>



<a name="178757579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757579">(Oct 22 2019 at 13:50)</a>:</h4>
<p>Notice that while it is UB to do that if the frames contain destructors, it isn't if they don't, yet that means that one would need to be able to unwind with a <code>Unwind_ForceUnwind</code> through a <code>nounwind</code> function.</p>



<a name="178757611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757611">(Oct 22 2019 at 13:50)</a>:</h4>
<p>Yes, this is arguably a mistake in LLVM's definition of <code>nounwind</code>.</p>



<a name="178757685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757685">(Oct 22 2019 at 13:51)</a>:</h4>
<p>I think what you propose for <code>extern "C"</code> is fine, but we should focus on what semantics make sense for Rust first, and worry what LLVM-IR we generate about it "on the side"</p>



<a name="178757721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757721">(Oct 22 2019 at 13:51)</a>:</h4>
<p>In particular for <code>#[no_unwind]</code></p>



<a name="178757791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757791">(Oct 22 2019 at 13:52)</a>:</h4>
<p>It would be fine to say that unwinding from a <code>#[no_unwind]</code> function is UB in Rust</p>



<a name="178757808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757808">(Oct 22 2019 at 13:52)</a>:</h4>
<p>and if someone uses <code>longjmp</code>, then they just can't use <code>#[no_unwind]</code></p>



<a name="178757907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757907">(Oct 22 2019 at 13:53)</a>:</h4>
<p>I'm happy with that.</p>



<a name="178757986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178757986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178757986">(Oct 22 2019 at 13:54)</a>:</h4>
<p>I'm happy to I think.</p>



<a name="178758001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178758001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178758001">(Oct 22 2019 at 13:54)</a>:</h4>
<p>By the way I've just done a little searching and it seems that pthread_exit (which uses unwinding in glibc) has poor interactions with <code>noexcept</code>.</p>



<a name="178758028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178758028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178758028">(Oct 22 2019 at 13:54)</a>:</h4>
<p>But I think this has been fixed now.</p>



<a name="178758030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178758030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178758030">(Oct 22 2019 at 13:54)</a>:</h4>
<p>The issue of leaving the Rust unwinding ABI unspecified could be then just solved by enforcing the translation at the <code>extern "C"</code> ABI layer</p>



<a name="178758110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178758110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178758110">(Oct 22 2019 at 13:55)</a>:</h4>
<blockquote>
<p>By the way I've just done a little searching and it seems that pthread_exit (which uses unwinding in glibc) has poor interactions with noexcept.</p>
</blockquote>
<p>I think that this is simpler to workaround in Rust, since these exceptions are foreign, and we can just not catch them ever, not even by the <code>abort-on-panic</code> shims at the <code>#[no_unwind] extern "C"</code> boundary</p>



<a name="178758174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178758174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178758174">(Oct 22 2019 at 13:56)</a>:</h4>
<p>That might mean that when such a function unwinds due to a <code>pthread_exit</code>, not all destructors might be run though :/</p>



<a name="178758230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178758230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178758230">(Oct 22 2019 at 13:56)</a>:</h4>
<p>So then we are back to whether there are some situations for which a <code>#[no_unwind]</code> function can unwind</p>



<a name="178758341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178758341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178758341">(Oct 22 2019 at 13:58)</a>:</h4>
<p>That's a bad idea, if someone calls <code>pthread_exit</code>, then no function in the stack can be <code>#[no_unwind]</code>, I'd be fine with that</p>



<a name="178759351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178759351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178759351">(Oct 22 2019 at 14:08)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;pthread.h&gt;</span><span class="cp"></span>

<span class="kt">void</span><span class="o">*</span> <span class="nf">thread</span><span class="p">(</span><span class="kt">void</span><span class="o">*</span><span class="p">)</span> <span class="k">noexcept</span> <span class="p">{</span>
  <span class="n">pthread_exit</span><span class="p">(</span><span class="nb">NULL</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="n">pthread_t</span> <span class="n">t</span><span class="p">;</span>
  <span class="n">pthread_create</span><span class="p">(</span><span class="o">&amp;</span><span class="n">t</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="kr">thread</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
  <span class="n">pthread_join</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>



<a name="178759369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178759369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178759369">(Oct 22 2019 at 14:09)</a>:</h4>
<p>This program crashes with:</p>
<div class="codehilite"><pre><span></span>terminate called without an active exception
[1]    601165 abort (core dumped)  ./a.out
</pre></div>



<a name="178763720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178763720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178763720">(Oct 22 2019 at 14:56)</a>:</h4>
<p>Should it crash?</p>



<a name="178763748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178763748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178763748">(Oct 22 2019 at 14:56)</a>:</h4>
<p>(What if instead of phtread_exit, a cancellation point + pthread_cancel are used ?)</p>



<a name="178766243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178766243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178766243">(Oct 22 2019 at 15:22)</a>:</h4>
<p>If you remove the <code>noexcept</code> it works fine. What happens is that <code>noexcept</code> catches any exceptions from within the function and calls <code>std::terminate</code>.</p>



<a name="178766265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178766265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178766265">(Oct 22 2019 at 15:22)</a>:</h4>
<p>A cancellation point does the same thing as <code>pthread_exit</code>, they're both forced unwinds.</p>



<a name="178767100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178767100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178767100">(Oct 22 2019 at 15:31)</a>:</h4>
<p>By the way all of this only applies to glibc, musl doesn't use unwinding for cancellation.</p>



<a name="178767945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178767945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178767945">(Oct 22 2019 at 15:41)</a>:</h4>
<p>I understand why the call to <code>std::terminate</code> happens, what I'm asking is if this is actually is the correct behavior, or if this behavior is by design</p>



<a name="178767973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178767973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178767973">(Oct 22 2019 at 15:41)</a>:</h4>
<p>For example, in Rust we can make <code>#[no_unwind]</code> functions <code>abort</code> when <code> longjmp</code> is used on Windows</p>



<a name="178767990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178767990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178767990">(Oct 22 2019 at 15:41)</a>:</h4>
<p>Or when <code>pthread_exit</code> and similar are used on Linux</p>



<a name="178768070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178768070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178768070">(Oct 22 2019 at 15:42)</a>:</h4>
<p>But we can also just unwind those functions just like msvc does for <code>longjmp</code>+<code>noexcept</code> in C++ code</p>



<a name="178768171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178768171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178768171">(Oct 22 2019 at 15:43)</a>:</h4>
<p>which is in fact we currently do for <code>extern "C"</code> function definitions that are <code>nounwind</code> on windows</p>



<a name="178768250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178768250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178768250">(Oct 22 2019 at 15:44)</a>:</h4>
<p>If the unwind is due to a <code>longjmp</code> on windows, instead of <code>abort</code>ing on abort-on-panic-shims, we let the unwind continue</p>



<a name="178768274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178768274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178768274">(Oct 22 2019 at 15:44)</a>:</h4>
<p>and some libraries like rlua rely on this working</p>



<a name="178768306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178768306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178768306">(Oct 22 2019 at 15:45)</a>:</h4>
<p>On Linux, we could do the same, e.g., if the unwind is due to a force unwind, not abort on abort-on-panic-shims.</p>



<a name="178769053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178769053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178769053">(Oct 22 2019 at 15:54)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span>  an alternative is making <code>#[no_unwind]</code> functions always abort on unwinding including for force unwinds, asynchronous exceptions, etc. and maybe say that <code>longjmp</code>s over these are UB.</p>



<a name="178900018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178900018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178900018">(Oct 23 2019 at 21:45)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> do you have some time to skim this thread and let us know if you have any immediate objections to the proposal of letting unwinding through <code>extern "C"</code> happen, and considering it implementation-defined, pending LLVM confirmation that the behavior on their end is well defined?</p>



<a name="178900804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178900804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178900804">(Oct 23 2019 at 21:56)</a>:</h4>
<p>I do have objections.</p>
<p>- It's debatable whether allowing <code>extern "C"</code> code to unwind is a breaking change or not (there's an argument that you cannot do negative reasoning about undefined behavior but to some extent I think such reasoning is legitimate).<br>
- Existing code is written with an assumption that <code>extern "C"</code> emits nounwind for code size and other benefits.<br>
- Making unwind-allowed the default makes it all the more likely that we freeze the unwinding implementation for Rust.<br>
- "Implementation defined" entails that e.g. for the <code>x86_64-unknown-linux-gnu</code>target, the compiler team is free to define the behavior. Given that we currently have one backend and one compiler I think that makes it in practice not implementation defined but defined for the whole language. I also think we should be free to change things for important tier-1 targets.<br>
- Given the back &amp; forth with respect to what LLVMs actual semantics are, I would want to see whatever guarantees we want from LLVM written directly into LangRef.<br>
- <code>no_unwind</code> is an attribute; this does not seem to cover function pointers.</p>



<a name="178900823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178900823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178900823">(Oct 23 2019 at 21:57)</a>:</h4>
<p>Also... we have a soundness hole to fix... (sooner rather than later)</p>



<a name="178901573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178901573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178901573">(Oct 23 2019 at 22:09)</a>:</h4>
<p>I don't think the "one backend and one compiler" issue really applies here: unwinding is pretty well standardized with SEH on Windows and libunwind/dwarf for all other platforms.</p>



<a name="178902213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178902213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178902213">(Oct 23 2019 at 22:18)</a>:</h4>
<p>Re: soundness, can we re-open RalfJ's PR to stop emitting <code>nounwind</code>?</p>



<a name="178902275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178902275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178902275">(Oct 23 2019 at 22:18)</a>:</h4>
<p>I am not sure I understand how this could be considered a breaking change. Does <code>rustc</code> actually make any promises with respect to optimization regressions? That would be surprising to me.</p>



<a name="178902663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178902663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178902663">(Oct 23 2019 at 22:25)</a>:</h4>
<blockquote>
<p>Re: soundness, can we re-open RalfJ's PR to stop emitting nounwind?</p>
</blockquote>
<p>I'm not going to say more than I've already said about this other than to note that <span class="user-mention" data-user-id="132920">@gnzlbg</span>  has a PR which fixes the soundness hole without changing the implementation UB to not UB.</p>



<a name="178902774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178902774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178902774">(Oct 23 2019 at 22:27)</a>:</h4>
<blockquote>
<p>Does rustc actually make any promises with respect to optimization regressions? That would be surprising to me.</p>
</blockquote>
<p>The reasoning here is that a set of behaviors are spec/implementation-UB and people could write code based on this assumption that such code will not occur (negative reasoning) for soundness.</p>



<a name="178902790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178902790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178902790">(Oct 23 2019 at 22:27)</a>:</h4>
<p>You could argue that such negative reasoning is dubious</p>



<a name="178907845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178907845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178907845">(Oct 23 2019 at 23:47)</a>:</h4>
<p>I understand how allowing <code>extern "C"</code> to unwind <em>now</em> and then prohibiting that in the future would be a breaking change, but that's not being proposed; essentially, the proposal here is to treat <code>extern "C"</code> the way we were planning to treat <code>extern "C unwind"</code>.</p>
<p>What I don't understand is your first bullet point, saying that permitting the unwind _now_ would be a breaking change. I can't think of any way that code could rely on the current behavior (not aborting but emitting <code>nounwind</code>) in a way that would be broken by no longer emitting <code>nounwind</code>. Am I misunderstanding that bullet point?</p>



<a name="178907951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178907951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178907951">(Oct 23 2019 at 23:49)</a>:</h4>
<p>Also, re: freezing the implementation, if we were to proceed with this plan, it would include requiring a translation layer at an <code>extern "C"</code> boundary if the default Rust panic mechanism ever changes, just like <code>extern "C unwind"</code> would have.</p>



<a name="178927609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178927609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178927609">(Oct 24 2019 at 07:32)</a>:</h4>
<p>I think that what <span class="user-mention" data-user-id="126931">@centril</span> is saying is that code may currently assume that FFI doesn't unwind and rely on this invariant for safety. If we change this to allow unwinding then such code may become unsound.</p>



<a name="178927645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178927645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178927645">(Oct 24 2019 at 07:33)</a>:</h4>
<p>That's a good argument, but I think its incorrect</p>



<a name="178927649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178927649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178927649">(Oct 24 2019 at 07:33)</a>:</h4>
<p>Currently, unwinding through <code>extern "C"</code> is UB</p>



<a name="178927664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178927664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178927664">(Oct 24 2019 at 07:33)</a>:</h4>
<p>This does not mean that code can be written to assume it will never happen</p>



<a name="178927724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178927724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178927724">(Oct 24 2019 at 07:34)</a>:</h4>
<p>UB is "we make no guarantees" and that includes "we do not gurantee that this will be UB forever"</p>



<a name="178927740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178927740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178927740">(Oct 24 2019 at 07:34)</a>:</h4>
<p>So defining that "UB" to say "unwinding is ok" is allowed</p>



<a name="178927755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178927755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178927755">(Oct 24 2019 at 07:34)</a>:</h4>
<p>Code that assumes otherwise is already broken, since it is expecting UB to be making some guarantees (e.g. that UB remains UB forever), which is something that we do not guarantee for UB - otherwise, we can't ever remove UB from the language.</p>



<a name="178928184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178928184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178928184">(Oct 24 2019 at 07:42)</a>:</h4>
<blockquote>
<p>I don't think the "one backend and one compiler" issue really applies here: unwinding is pretty well standardized with SEH on Windows and libunwind/dwarf for all other platforms.</p>
</blockquote>
<p>GCC 3 to GCC 4 changed the linux unwinding ABI from SJLJ to DWARF</p>



<a name="178928197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178928197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178928197">(Oct 24 2019 at 07:42)</a>:</h4>
<p>That wasn't that long ago</p>



<a name="178928274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/178928274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#178928274">(Oct 24 2019 at 07:44)</a>:</h4>
<p>I'd rather not commit to a solution that assumes that something like this will never happen again</p>



<a name="179020165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/179020165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#179020165">(Oct 25 2019 at 04:04)</a>:</h4>
<p>I just read through this whole thread, and the idea of allowing unwinding by default seems reasonable to me.</p>



<a name="179020176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/179020176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#179020176">(Oct 25 2019 at 04:05)</a>:</h4>
<p>Thank you for the detailed analysis, <span class="user-mention" data-user-id="143274">@Amanieu</span> .</p>



<a name="179036013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Allow%20unwinding%20from%20extern%20%22C%22%20by%20default/near/179036013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Allow.20unwinding.20from.20extern.20.22C.22.20by.20default.html#179036013">(Oct 25 2019 at 09:48)</a>:</h4>
<p>For what it's worth, I think opening the RFC with <code>extern "C unwind"</code> (and possibly even landing it) would not necessarily prevent us from making <code>extern "C"</code> match the proposed "C unwind" behavior. That's the main reason why I think we should proceed with "C unwind" for now.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>